package nl.hva.three2learn.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import org.hibernate.engine.internal.Cascade;

@Table(name = "question")
@Entity
public final class Question implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -5814535584569383329L;

	@Id
	@GeneratedValue
	@Column(name = "question_id")
	private long id;
	
	@Column(name = "question")
	private String question;
	
	@Column(name="answer")
	private String answer;
	
	@OneToMany(cascade = { CascadeType.DETACH, CascadeType.REMOVE })
	@LazyCollection(LazyCollectionOption.FALSE)
	private List<Answer> answers;
	
	@Column(name = "is_multiple_choice")
	private boolean isMultipleChoice;
	
	public Question(String question, List<Answer> answers, String answer, boolean isMultipleChoice) {
		this.question = question;
		this.answers = answers;
		this.answer = answer;
		this.isMultipleChoice = isMultipleChoice;
	}
	
	public Question() { }

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getQuestion() {
		return question;
	}

	public void setQuestion(String question) {
		this.question = question;
	}

	public List<Answer> getAnswers() {
		return answers;
	}

	public void setAnswers(List<Answer> answers) {
		this.answers = answers;
	}
	
	public void addAnswer(Answer answer) {
		this.answers.add(answer);
	}
	
	public boolean isMultipleChoice() {
		return isMultipleChoice;
	}

	public void setMultipleChoice(boolean isMultipleChoice) {
		this.isMultipleChoice = isMultipleChoice;
	}
	
	public String getAnswer() {
		return this.answer;
	}
	
	public void setAnswer(String answer) {
		this.answer = answer;
	}
}
